import logging
from redis import StrictRedis


class Config(object):
    """项目的配置"""
    # DEBUG = True

    SECRET_KEY = "isdpElS6WO5GWA5TuD/nLBhG71hYyaKpeY592qRs/ARz8XM9eGYErT3QZmz3IXI2"

    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 在请求结束时，如果指定此配置为true ，那么SQLAlchemy会自动执行一次db.session.commit()
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True


    # Redis 的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_POST = 6379

    # Session 保存配置
    SESSION_TYPE = 'redis'
    # 开启session签名
    SESSION_USE_SIGNR = True
    # 指定Session保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_POST)
    # 设置需要过期
    SESSION_PERMANENT = False
    # 设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2

    # 设置日志等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    # 开发环境下配置
    DEBUG = True


class ProductionConfig(Config):
    # 生产环境下配置
    DEBUG = False
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    # 单元测试环境下配置
    DEBUG = True
    TESTING = True


config = {
    "development": DevelopmentConfig,
    "production": ProductionConfig,
    "testing": TestingConfig
}
